package com.ssyt.ec.assit.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ssyt.ec.assit.entity.AssistNewNoticeEntity;
import com.ssyt.ec.assit.entity.PCEntity;
import com.ssyt.ec.assit.entity.UserPowerEntity;
import com.ssyt.ec.assit.service.AssistNewNoticeService;
import com.ssyt.ec.common.AppServlet;
import com.ssyt.ec.common.PageModel;
import com.ssyt.ec.common.util.FastjsonUtil;
import com.ssyt.ec.common.util.SysuserUtil;

@WebServlet("/AssistNewNoticeServlet")
public class AssistNewNoticeServlet extends AppServlet {
	private static final long serialVersionUID = 1L;
	private AssistNewNoticeService assistNewNoticeService = new AssistNewNoticeService();

	public AssistNewNoticeServlet() {
		super();

	}

	@Override
	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String command = request.getParameter("command");
		if ("listPosition".equals(command)) {
			listPosition(request, response);
		} else if ("listTest".equals(command)) {
			listTest(request, response);
		}else if("listNewCompanyInfo".equals(command)){
			listNewCompanyInfo(request, response);
		}else if("listUserPower".equals(command)){
			listUserPower(request, response);
		}
	}

	/**
	 * 公司招聘查询
	 * 
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	protected void listPosition(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		int page = Integer.parseInt(request.getParameter("page"));
		int rows = Integer.parseInt(request.getParameter("rows"));
		PageModel<AssistNewNoticeEntity> assistNewNoticeEntity = assistNewNoticeService
				.listPosition(page, rows);
		print(response, FastjsonUtil.toJson(assistNewNoticeEntity));
	}

	/**
	 * 测试
	 * 
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	protected void listTest(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		List<AssistNewNoticeEntity> assistNewNoticeEntity = assistNewNoticeService
				.listTest();
		print(response, FastjsonUtil.toJson(assistNewNoticeEntity));
	}
	
	/**
	 * 公司和职位详细查询
	 * 
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	protected void listNewCompanyInfo(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
   	       int id = Integer.parseInt( request.getParameter("id"));
	        PCEntity pcEntity = assistNewNoticeService.listNewCompany(id);
	        print(response, FastjsonUtil.toJson(pcEntity));
	}
	
	/**
	 * 主页面权限
	 * 
	 * @param request
	 * @param response
	 * @throws ServletException
	 * @throws IOException
	 */
	protected void listUserPower(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
   	       int userId = SysuserUtil.getUserId(request);
   	       UserPowerEntity userPowerEntity = assistNewNoticeService.listUserPower(userId);
   	       print(response, FastjsonUtil.toJson(userPowerEntity));
	}
	
}
